#include"mcu_config_timer.h"

void timer_init(void)
{
    //配置TIM1时基单元
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
    TIM_TimeBaseInitStructure.TIM_Prescaler = 7200-1; //预分频系数 72M/7200=10KHz
    TIM_TimeBaseInitStructure.TIM_Period = 5000-1; //计数周期 10KHz/5000=2Hz
    TIM_TimeBaseInitStructure.TIM_ClockDivision = 0; //时钟分频因子
    TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数模式
    TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 1-1; //重复计数次数
    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStructure);
    TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); //使能更新中断

    TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); //选择更新事件作为触发源
    
    TIM_Cmd(TIM1, ENABLE);
    
    //TIM3 用于触发ADC采样
    // TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure2;
    // TIM_TimeBaseInitStructure2.TIM_Prescaler = 3600-1; //预分频系数 72M/7200=10k
    // TIM_TimeBaseInitStructure2.TIM_Period = 10000-1; //计数周期 10k/10000=1Hz
    // TIM_TimeBaseInitStructure2.TIM_ClockDivision = 0; //时钟分频因子
    // TIM_TimeBaseInitStructure2.TIM_CounterMode = TIM_CounterMode_Up; //计数模式
    // TIM_TimeBaseInitStructure2.TIM_RepetitionCounter = 1-1; //重复计数次数
    // TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure2);
    // TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update); //选择更新事件作为触发源
    // TIM_Cmd(TIM3, ENABLE);
}